<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="计划名称" prop="examinationPlanName">
        <el-input
          v-model="queryParams.examinationPlanName"
          placeholder="请输入计划名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:post:add']"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="tableData"
    >
      <el-table-column
        prop="examinationPlanName"
        label="计划名称"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="examinationTime" label="执行时间" align="center">
      </el-table-column>
      <el-table-column prop="passScore" label="及格分数" align="center">
      </el-table-column>
      <el-table-column prop="totalScore" label="总分数" align="center">
      </el-table-column>
      <el-table-column prop="referenceNumber" label="参考人数" align="center">
      </el-table-column>
      <el-table-column prop="referenceStatus" label="执行状态" align="center">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.referenceStatus == 0 ? 'danger' : 'success'"
            disable-transitions
            >{{ scope.row.referenceStatus == 0 ? "未完成" : "已完成" }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="createLink(scope.row)"
            >生成链接</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="getInfo(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <ExaminationInfo ref="ExaminationInfoRef"></ExaminationInfo>
    <TrainLink ref="TrainLinkRef"></TrainLink>
  </div>
</template>

<script>
import {
  getTeacherExaminationPlanList,
  delExaminationPlan,
} from "@/api/train/index.js";
import ExaminationInfo from './components/examination-info.vue';
import TrainLink from './components/train-link.vue'
export default {
  components: {
    ExaminationInfo,
    TrainLink
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      tableData: [],
       // 总条数
       total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: 1,
        referenceStatus:0,
        examinationPlanName:null,
        orderByColumn: "create_time",
        isAsc: "desc",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    createLink(row){
      this.$refs.TrainLinkRef.show(row);
    },
    /** 查询计划列表 */
    getList() {
      this.loading = true;
      getTeacherExaminationPlanList(this.queryParams).then((res) => {
        console.log(res);
        if (res.code === 200) {
          this.tableData = res.rows;
          this.total = res.total;
          this.loading = false;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
   
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加岗位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const postId = row.postId || this.ids;
      getPost(postId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改岗位";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPost(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleDelete(row) {
      delExaminationPlan({
        examinationPlanId: row.examinationPlanId,
      }).then((res) => {
        console.log(res);
        if (res.code === 200) {
          this.getList();
        }
      });
    },
     //详情
     getInfo(row) {
      this.$refs.ExaminationInfoRef.show(row.examinationPlanId);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/post/export",
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
